﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using StripeOne.Core.Tools;

namespace StripeOne.ShortenUrl.Business
{
    public class ShortenBusiness
    {
        public static string GenerateUrlCode()
        {
            var result = "";
            using (MD5 md5Hash = MD5.Create())
            {
                string input = DateTime.Now.Ticks.ToString();
                byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));

                for (int i = 0; i < data.Length; i++)
                {
                    result += data[i].ToString("x2");
                }
            }

            var rdnStart = new Random();
            rdnStart.Next(0, 20);

            return result.Substring(rdnStart.ToInt32(), rdnStart.ToInt32() + 8);
        }
    }
}
